
import { _decorator, Component, Node, PhysicsSystem2D, Vec2, RaycastResult2D } from 'cc';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = MoveObject
 * DateTime = Tue Jan 11 2022 13:08:59 GMT+0800 (中国标准时间)
 * Author = lyps
 * FileBasename = MoveObject.ts
 * FileBasenameNoExtension = MoveObject
 * URL = db://assets/Scripts/MoveObject.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
 
@ccclass('MoveObject')
export class MoveObject extends Component {
    protected rayCastRadius = 8;
    public ATK = 0;
    start () {
        // [3]
    }

    update(deltaTime:number){
        this.onRayCast(this.rayCast())
    }

    //射线检测
    protected rayCast() {
        let rays:Readonly<RaycastResult2D[]>[] = [];
        rays.push(PhysicsSystem2D.instance.raycast(new Vec2(this.node.position.x,this.node.position.y),new Vec2(this.node.position.x,this.node.position.y+this.rayCastRadius)));
        rays.push(PhysicsSystem2D.instance.raycast(new Vec2(this.node.position.x,this.node.position.y),new Vec2(this.node.position.x-this.rayCastRadius,this.node.position.y)));
        rays.push(PhysicsSystem2D.instance.raycast(new Vec2(this.node.position.x,this.node.position.y),new Vec2(this.node.position.x,this.node.position.y-this.rayCastRadius)));
        rays.push(PhysicsSystem2D.instance.raycast(new Vec2(this.node.position.x,this.node.position.y),new Vec2(this.node.position.x+this.rayCastRadius,this.node.position.y)));
        return rays;
    }

    protected onRayCast(rays:Readonly<RaycastResult2D[]>[]){
        
    };
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/ccclass.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
